<script setup>
import { ref } from 'vue';


const userInfo = ref({
    username:'',
    email:'',
    createTime:'',
    avatar:''
})

import { showUserInfoService, updateUserInfoService } from '@/api/user';
import { ElMessage } from 'element-plus';

import useUserInfoStoken  from '@/stores/userInfo.js';
const userInfoStoken = useUserInfoStoken();

//显示当前登录用户的信息
const showUserInfo = async()=>{
    let result = await showUserInfoService();
    userInfo.value = result.data;
}

showUserInfo();

//修改用户信息
const updateUserInfo = async()=>{
    let result = await updateUserInfoService(userInfo.value);
    ElMessage.success(result.message ? result.message : '修改成功')
    userInfoStoken.setInfo(userInfo.value);
    showUserInfo();
}

</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="userInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="登录名称">
                        <el-input v-model="userInfo.username"></el-input>
                    </el-form-item>
                    <el-form-item label="用户邮箱" prop="email">
                        <el-input v-model="userInfo.email"></el-input>
                    </el-form-item>
                    <el-form-item label="注册时间" prop="createTime">
                        <el-input v-model="userInfo.createTime" disabled></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updateUserInfo">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>
